package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private SmallVideosService smallVideosService;

    @PostMapping //发布小视频的方法 接收两个参数          ↓封面图                 ↓视频
    public ResponseEntity smallVideos(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {
        //该方法没有返回值
        //1.调用service处理
        smallVideosService.video(videoThumbnail,videoFile);
        //2.返回参数
        return ResponseEntity.ok(null);
    }


    @GetMapping//查询短视频列表
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1")Integer page,
                                      @RequestParam(defaultValue = "10")Integer pagesize){
        //1.接收分页参数
        //2.调用service处理参数，返回一个PageResult对象，该对象里装的是一个VideoVo对象
        PageResult vo=smallVideosService.findList(page,pagesize);
        return ResponseEntity.ok(vo);
    }


    @PostMapping("/{id}/like")//视频点赞，其中没有业务代码
    public ResponseEntity like(@PathVariable("id") String videoId){
        //1.接收参数
        //2.电影service处理
        smallVideosService.like(videoId);
        //3.返回参数,前端不需要返回值
        return ResponseEntity.ok(null);
    }
}
